<?php

// ensure this file is being included by a parent file
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

if($_GET['letra'] == ""){
	$seleccion = "a";
}else{
	$seleccion = mysql_real_escape_string($_GET['letra']);
}


$pendientes="SELECT * FROM jos_directorio where aprobado = false order by insertado desc";
$lista="SELECT * FROM jos_directorio where aprobado = true and apellidos like '$seleccion%' order by apellidos desc";

switch( $act ) {
    case 'pendiente':
        doPendientes();
        break;
    case 'aprobar':
        doAprobar();
        break;
    case 'borrar':
        doBorrar();
        break;
    default:
        doLista();
        break;
}

function doLista()
{
    global $database, $pendientes, $lista;
    $database->setQuery($lista);
    $rows = $database->loadObjectList();
    
    global $seleccion;

    $view = 'lista';
    include("admin.directorio.html.php");
}

function doPendientes()
{
    global $database, $pendientes, $lista;
    $database->setQuery($pendientes);
    $rows = $database->loadObjectList();
    $view = 'pendientes';
    include("admin.directorio.html.php");
}

function doAprobar(){
    global $database, $pendientes, $lista;
    $id = $_GET['id'];
    $database->setQuery("UPDATE jos_directorio SET aprobado=true where ID = $id ");
    $database->query();
    
    $anterior=$_GET['anterior'];
    if($anterior=='lista') $database->setQuery($lista);
    else $database->setQuery($pendientes);
    $rows = $database->loadObjectList();
    $view = $anterior;
    include("admin.directorio.html.php");
}

function doBorrar(){
    global $database, $pendientes, $lista;
    $id = $_GET['id'];
    $database->setQuery("DELETE FROM jos_directorio where ID = $id ");
    $database->query();
    
    $anterior=$_GET['anterior'];
    if($anterior=='lista') $database->setQuery($lista);
    else $database->setQuery($pendientes);
    $rows = $database->loadObjectList();
    $view = $anterior;
    include("admin.directorio.html.php");
}

?>
